[//
    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json;charset=UTF-8';
        let $DATA = Object.assign({},this.$DATA);
        let $features = await Kuoplus(kuo.class);
        let $THIS =  this;
        let $_GET = kuo.get;
        let $LANG = this.LANG();
        let $tuid = $_GET['tuid'] ?$_GET['tuid']:0;//推广uid
        let $appid  = $features['configure']['开放平台'] && $features['configure']['开放平台']['0']?$features['configure']['开放平台']['0']:"";
        let $secret  = $features['configure']['开放平台'] && $features['configure']['开放平台']['1']?$features['configure']['开放平台']['1']:"";
        let UID = 0;
        let $USER = null;
        let $code = $_GET['code']?$_GET['code']:"";
        let $Security = await Mem.Get('session/'+kuo.sessionid);
        if(!$Security ){
            $Security={
                uid:0,
                code:0,
                tuid:0
            };
        }
        let $fan = await GET('https://api.weixin.qq.com/sns/oauth2/access_token?appid='+$appid+'&secret='+$secret+'&code='+$code+'&grant_type=authorization_code');
        $fan = json_decode($fan);
        if($fan['errcode']){
            $DATA.code = -1;$DATA.data =$fan['errcode']; $DATA.msg = $fan['errmsg'];Context.body = JSON.stringify($DATA);
            return ; 
        }
        let $openid = $fan['openid']?$fan['openid']:"";
        let $unionid = $fan['unionid']?$fan['unionid']:"";
        let $access_token = $fan['access_token']?$fan['access_token']:"";
        if($unionid == ""){
            $DATA.code = -1;$DATA.data =$fan['error']; $DATA.msg = $LANG.unionid;Context.body = JSON.stringify($DATA);
            return ;
        }
        $Security['openid'] = $openid;
        let $db =  await db('login_weixin');
        let $user = await $db.Where( {'unionid': $unionid } ).Find();
        if( $user ){
            if($user['openido'] == ""){
                await $db.Where( {'unionid': $unionid } ).Update( {'openido':$openid});
            }
            $USER =  await Uid($user['uid']);
            if($USER['accountoff'] != 1){
                $DATA.code = -1;  $DATA.msg = $LANG.accountoff;Context.body = JSON.stringify($DATA);
                return ;
            }
            $Security['uid'] = $user['uid'];
            await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
            await  Kuolog('userlog',$user['uid'],0, [] ,kuo.func_,kuo.class,kuo.ip);
            
            $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
            $DATA.code = 1;
            $DATA.msg = $LANG.login_true;
            $DATA.data = $USER;
            $DATA.apptoken = kuo.sessionid;
            Context.body = JSON.stringify($DATA);
            return ;
        }

        if($Security.uid && $Security.uid  > 0){
            //绑定用户
            UID = $Security.uid;
            let $chaxun = await $db.Where( {'uid': UID} ).Find();
            if($chaxun){
                $DATA.code = -1;  $DATA.msg = $LANG.account_false;Context.body = JSON.stringify($DATA);
                return ;
            }

        }else{
    
            $fan = await GET('https://api.weixin.qq.com/sns/userinfo?access_token='+$access_token+'&openid='+$openid+'&lang=zh_CN');
            $fan = json_decode($fan);
            if(!$fan['openid']){
                $fan = {
                    'nickname': $openid,
                    'sex' : -1,
                    'headimgurl':''
                }; 
            }
            $user = {
                'nickname':$fan['nickname']?$fan['nickname']:$openid,
                'sex':$fan['sex']?$fan['sex']:-1,
                'headimgurl':$fan['headimgurl']?$fan['headimgurl']:""
            };
        
            let $SEX = { "-1":"1", "1":"1","2":"0"};
            UID = await $THIS.REG({
                "name":$user.nickname,
                "sex":   $SEX [$user['sex']]?$SEX [$user['sex']]:-1,
                "tou": $user.headimgurl,
                "ip":kuo.ip,
                'tuid':$tuid
            });
        }
        if(!UID || UID < 1){
            $DATA.code = -1; $DATA.msg = $LANG.uuid_error;Context.body = JSON.stringify($DATA);
            return ;
        }
        $user = {
            'openido':$openid,
            'unionid':$unionid,
            'uid': UID
        };
        $fan = $db.Insert($user);
        if($fan){
            $Security['uid'] = $user['uid'];
            await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
            await  Kuolog('userlog',$user['uid'],0, [],kuo.func_,kuo.class,kuo.ip);
            $USER = await Uid( $user['uid'] );
            $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
            $DATA.code = 1;
            $DATA.msg = $LANG.reg_true;
            $DATA.data = $USER;
            $DATA.apptoken = kuo.sessionid;
            Context.body = JSON.stringify($DATA);
        }else{
            $DATA.code = -1;
            $DATA.msg = $LANG.reg_false;
            Context.body = JSON.stringify($DATA);
        }
    } 
]